//
//  JCCPrivacyViewController.swift
//  剂查查
//
//  Created by xianquan on 2024/12/13.
//  Copyright © 2024 shipin. All rights reserved.
//

import CommonTools
import TYUIKit

class JCCPrivacyViewController: BaseViewController {
    
    var type: PvivacyType = .privacy
    

    override func viewDidLoad() {
        super.viewDidLoad()

        setTitle(type.title)
        
        let tv = UITextView()
        tv.isEditable = false
        tv.showsVerticalScrollIndicator = false
        view.addSubview(tv)
        tv.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: TY_NaviBarHeight() , left: 8, bottom: 0, right: 8))
        }
        showLoading()
        NetworkRequest<Any>.request(networkType: .getTreaty(type: type.rawValue)) { result in
            hideLoading()
            switch result {
            case .success(let response):
                guard let response = response as? [String: Any], let htmlStr = response["data"] as? String else {return}
                let htmlString = "\n\(htmlStr)"
                let att = (try? NSMutableAttributedString(data: htmlString.data(using: .unicode)!, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)) ?? NSMutableAttributedString(string: htmlString)
                att.yy_font = 15.regular
                
                DispatchQueue.main.asyncAfter(deadline: .now()) {
                    tv.scrollToTop(animated: false)
                }
                tv.attributedText = att
            case .failure(let error):
                XWLog(value: error)
            }
        }
        
        
        
    }
    


}
